<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css"
          integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
    <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"
            integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
            crossorigin="anonymous"></script>

</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-2 col-md-offset-3" id="btn">
            <button type="button" class="btn btn-success" style="margin: 20px 0 10px 0" onclick="toAdd()">新增</button>
        </div>
        <div class="col-xs-4 col-md-offset-2">
            <button type="button" class="btn btn-link" style="margin: 20px 0 10px 0"
                    th:text="${#session.getAttribute('userLogin').getEname()}"></button>
            <button type="button" class="btn btn-link" style="margin: 20px 0 10px 0" onclick="toIndex()">返回首页
            </button>
            <button type="button" class="btn btn-link" style="margin: 20px 0 10px 0" onclick="logOut()">注销</button>
        </div>
        <div class="col-xs-6 col-md-offset-3">
            <table class="table table-hover table-bordered table-condensed">
                <tr>
                    <th>部门编号</th>
                    <th>部门名称</th>
                    <th>地理位置</th>
                    <th>操作</th>
                </tr>
                <tr th:each="dept : ${deptList}">
                    <td th:text="${dept.deptNo==null?'无':dept.deptNo}"></td>
                    <td th:text="${dept.dname==null?'无':dept.dname}"></td>
                    <td th:text="${dept.loc==null?'无':dept.loc}"></td>
                    <td colspan="2">
                        <button type="button" class="btn btn-warning"
                                th:onclick="'toUpdate(\'' + ${dept.deptNo} + '\')'">
                            编辑
                        </button>
                        <button type="button" class="btn btn-danger" th:onclick="'del(\'' + ${dept.deptNo} + '\')'">删除
                        </button>
                    </td>
                </tr>
            </table>
        </div>
    </div>
</div>

</body>
<script>
    function del(deptNo) {
        if (confirm("确定要删除吗？")) {
            window.location.href = "/dept/delDept?deptNo=" + deptNo;
        }
    }

    function toUpdate(deptNo) {
        window.location.href = "/dept/toUpdate?deptNo=" + deptNo;
    }

    function toAdd() {
        window.location.href = "add.html";
    }

    function toIndex() {
        window.location.href = "/index.html";
    }

    function logOut() {
        window.location.href = "/user/logOut";
    }
</script>

</html>